package com.bbs.service.impl;

import com.bbs.dao.CommentDao;
import com.bbs.dao.ReplyDao;
import com.bbs.entity.Comment;
import com.bbs.entity.Post;
import com.bbs.entity.Reply;
import com.bbs.entity.Topic;
import com.bbs.service.ReplyService;
import com.bbs.utils.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Component("replyService")
public class ReplyServiceImpl implements ReplyService {
    @Autowired
    private ReplyDao replyDao;
    @Autowired
    private CommentDao commentDao;

    Post post = new Post();

    //帖子详情
    @Override
    public List<Reply> findAllReply(int id) {
        List<Reply>  replyList = replyDao.findAllReply(id);
        for(Reply r:replyList){
            List<Comment> commentList=commentDao.loulouUser(r.getId());
            r.setCommentList(commentList);
        }
//        List<Reply> replyList = replyDao.findAllReply(id);
        return replyList;
    }

    @Override
    public int insertReply(Reply reply) {
        reply.setReplyTime(MyUtil.formatDate(new Date()));
        int flag = replyDao.insertReply(reply);

        return flag;
    }

    @Override
    public int updatePostReplyTime(Reply reply) {
        post.setReplyTime(MyUtil.formatDate(new Date()));
        replyDao.updatePostReplyTime(reply);
        return 0;
    }

    @Override
    public int updatePostReplyCount(Reply reply) {
        replyDao.updatePostReplyCount(reply);
        return 0;
    }


}
